//
//  IntroducedViewController.m
//  豆瓣
//
//  Created by aaaaaa on 16/6/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "IntroducedViewController.h"
#import "ActivityModel.h"
#import "Tools.h"
#import "UIImageView+WebCache.h"
#import "OwnerModel.h"

@interface IntroducedViewController ()

@end

@implementation IntroducedViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self config];
    
    [self createScrollView];
}

- (void)config{
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = self.activityModel.title;
    self.automaticallyAdjustsScrollViewInsets = NO;
    

    
    self.navigationItem.leftBarButtonItem = LEFTBAR;
    

    self.navigationItem.rightBarButtonItem = RIGHTBAR;
    
    
}

- (void)leftBarAction:(UIBarButtonItem *)bar{
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)rightBarAction:(UIBarButtonItem *)bar{
    
}


- (void)createScrollView{
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 64, self.view.bounds.size.width - 40, self.view.bounds.size.height - 64 - 50)];
    
    scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:scrollView];
    [scrollView release];
    
    //标题
    UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, scrollView.bounds.size.width, 40)];
    titleLable.text = self.activityModel.title;
    titleLable.font = [UIFont systemFontOfSize:24];
//    titleLable.backgroundColor = [UIColor redColor];
    [scrollView addSubview:titleLable];
    
    //图片
    CGFloat imageHeight = [Tools getImageHeight:self.activityModel.image withWidth:scrollView.bounds.size.width * 0.3];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10 + 40, scrollView.bounds.size.width * 0.3, imageHeight)];
    [imageView sd_setImageWithURL:[NSURL URLWithString:self.activityModel.image]];
    [scrollView addSubview:imageView];
    
    //时间地点...
    UIView *iconView = [[UIView alloc] initWithFrame:CGRectMake(scrollView.bounds.size.width * 0.3 + 10, 10 + 40, scrollView.bounds.size.width * 0.7 - 10, imageHeight)];
    NSArray *iconNameArray = @[@"icon_date_blue", @"icon_sponsor_blue", @"icon_catalog_blue", @"icon_spot_blue"];
    
    NSDate *startDate = [Tools returnDate:self.activityModel.begin_time];
    NSDate *endDate = [Tools returnDate:self.activityModel.end_time];
    
    NSString *startStr = [Tools returnString:startDate];
    NSString *endStr = [Tools returnString:endDate];
    
    NSString *dateStr = [NSString stringWithFormat:@"%@ -- %@", startStr, endStr];
    NSString *typeStr = [NSString stringWithFormat:@"类型：%@", self.activityModel.category_name];
    
    NSArray *iconContentArray = @[dateStr, self.activityModel.owner.name, typeStr, self.activityModel.address];
    for (int i = 0; i < 4; i++) {
        UIImageView *iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 25 * i, 25, 25)];
        iconImageView.image = IMAGE(iconNameArray[i], @"png");
        
        [iconView addSubview:iconImageView];
        [iconImageView release];
        
        CGFloat textHeight = [Tools getTextHeight:iconContentArray[i] withWidth:iconView.bounds.size.width - 25 withFontSize:16];
        UILabel *iconLable = [[UILabel alloc] initWithFrame:CGRectMake(25, 25 * i, iconView.bounds.size.width - 25, textHeight)];
        iconLable.text = iconContentArray[i];
        iconLable.numberOfLines = 0;
        iconLable.font = [UIFont systemFontOfSize:16];
        
        [iconView addSubview:iconLable];
        [iconLable release];
        
    }
    
    [scrollView addSubview:iconView];
    [iconView release];

    
    
    UILabel *activityTitleLable = [[UILabel alloc] initWithFrame:CGRectMake(0, imageHeight + 40 + 20, scrollView.bounds.size.width, 40)];
    activityTitleLable.text = @"活动介绍";
    activityTitleLable.font = [UIFont systemFontOfSize:24];
    [scrollView addSubview:activityTitleLable];
    
    
    
    CGFloat contentHeight = [Tools getTextHeight:self.activityModel.content withWidth:scrollView.bounds.size.width withFontSize:16];
    
    UILabel *contentLable = [[UILabel alloc] initWithFrame:CGRectMake(0, imageHeight + 40 + 20 + 40, scrollView.bounds.size.width, contentHeight)];
    contentLable.text = self.activityModel.content;
    contentLable.numberOfLines = 0;
    contentLable.font = [UIFont systemFontOfSize:16];
    
    [scrollView addSubview:contentLable];
    
    scrollView.contentSize = CGSizeMake(0, imageHeight + contentHeight + 40 + 20 + 40);
    
}
















- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
